﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ZK.Common.IConfig;

namespace ZK.Common
{
    public class IConfig : ConfigurationSection
    {


        #region MHSNReader
        [ConfigurationProperty("MHSNReader", IsRequired = false)]
        public HaredWareCommonM MHSNReaderE
        {
            get { return (HaredWareCommonM)this["MHSNReader"]; }
        }

        public static HaredWareCommonM GetSetMHSNReader
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).MHSNReaderE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.MHSNReaderE.BaudRate = value.BaudRate;
                iConfig.MHSNReaderE.DataBits = value.DataBits;
                iConfig.MHSNReaderE.PortName = value.PortName;
                iConfig.MHSNReaderE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region TrafficLightH
        [ConfigurationProperty("TrafficLightH", IsRequired = false)]
        public HaredWareCommonM TrafficLightHE
        {
            get { return (HaredWareCommonM)this["TrafficLightH"]; }
        }

        public static HaredWareCommonM GetSetTrafficLightH
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).TrafficLightHE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.TrafficLightHE.BaudRate = value.BaudRate;
                iConfig.TrafficLightHE.DataBits = value.DataBits;
                iConfig.TrafficLightHE.PortName = value.PortName;
                iConfig.TrafficLightHE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region TrafficLightQ
        [ConfigurationProperty("TrafficLightQ", IsRequired = false)]
        public HaredWareCommonM TrafficLightQE
        {
            get { return (HaredWareCommonM)this["TrafficLightQ"]; }
        }
        public static HaredWareCommonM GetSetTrafficLightQ
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).TrafficLightQE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.TrafficLightQE.BaudRate = value.BaudRate;
                iConfig.TrafficLightQE.DataBits = value.DataBits;
                iConfig.TrafficLightQE.PortName = value.PortName;
                iConfig.TrafficLightQE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region Infrared
        [ConfigurationProperty("Infrared", IsRequired = false)]
        public HaredWareCommonM InfraredE
        {
            get { return (HaredWareCommonM)this["Infrared"]; }
        }

        public static HaredWareCommonM GetSetInfrared
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).InfraredE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.InfraredE.BaudRate = value.BaudRate;
                iConfig.InfraredE.DataBits = value.DataBits;
                iConfig.InfraredE.PortName = value.PortName;
                iConfig.InfraredE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region DLZC
        [ConfigurationProperty("DLZC", IsRequired = false)]
        public HaredWareCommonM DLZCE
        {
            get { return (HaredWareCommonM)this["DLZC"]; }
        }

        public static HaredWareCommonM GetSetDLZC
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).DLZCE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.DLZCE.BaudRate = value.BaudRate;
                iConfig.DLZCE.DataBits = value.DataBits;
                iConfig.DLZCE.PortName = value.PortName;
                iConfig.DLZCE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region WagonBalance
        [ConfigurationProperty("WagonBalance", IsRequired = false)]
        public HaredWareCommonM wagonBalanceE
        {
            get { return (HaredWareCommonM)this["WagonBalance"]; }
        }

        public static HaredWareCommonM GetSetwagonBalance
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).wagonBalanceE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.wagonBalanceE.BaudRate = value.BaudRate;
                iConfig.wagonBalanceE.DataBits = value.DataBits;
                iConfig.wagonBalanceE.PortName = value.PortName;
                iConfig.wagonBalanceE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesQ
        [ConfigurationProperty("CameraScalesQ", IsRequired = false)]
        public HaredWareCommonM CameraScalesQE
        {
            get { return (HaredWareCommonM)this["CameraScalesQ"]; }
        }

        public static HaredWareCommonM GetSetCameraScalesQ
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesQE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CameraScalesQE.Ip = value.Ip;
                iConfig.CameraScalesQE.Port = value.Port;
                iConfig.CameraScalesQE.UserName = value.UserName;
                iConfig.CameraScalesQE.PassWord = value.PassWord;
                iConfig.CameraScalesQE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region LedQ
        [ConfigurationProperty("LedQ", IsRequired = false)]
        public HaredWareCommonM LedQE
        {
            get { return (HaredWareCommonM)this["LedQ"]; }
        }

        public static HaredWareCommonM GetSetLedQ
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).LedQE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.LedQE.Ip = value.Ip;
                iConfig.LedQE.Height = value.Height;
                iConfig.LedQE.Width = value.Width;
                iConfig.LedQE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region LedH
        [ConfigurationProperty("LedH", IsRequired = false)]
        public HaredWareCommonM LedHE
        {
            get { return (HaredWareCommonM)this["LedH"]; }
        }

        public static HaredWareCommonM GetSetLedH
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).LedHE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.LedHE.Ip = value.Ip;
                iConfig.LedHE.Height = value.Height;
                iConfig.LedHE.Width = value.Width;
                iConfig.LedHE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region LedDC
        [ConfigurationProperty("LedDC", IsRequired = false)]
        public HaredWareCommonM LedDCE
        {
            get { return (HaredWareCommonM)this["LedDC"]; }
        }

        public static HaredWareCommonM GetSetLedDC
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).LedDCE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.LedDCE.Ip = value.Ip;
                iConfig.LedDCE.Height = value.Height;
                iConfig.LedDCE.Width = value.Width;
                iConfig.LedDCE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesH
        [ConfigurationProperty("CameraScalesH", IsRequired = false)]
        public HaredWareCommonM CameraScalesHE
        {
            get { return (HaredWareCommonM)this["CameraScalesH"]; }
        }

        public static HaredWareCommonM GetSetCameraScalesH
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesHE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CameraScalesHE.Ip = value.Ip;
                iConfig.CameraScalesHE.Port = value.Port;
                iConfig.CameraScalesHE.UserName = value.UserName;
                iConfig.CameraScalesHE.PassWord = value.PassWord;
                iConfig.CameraScalesHE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesG1
        [ConfigurationProperty("CameraScalesG1", IsRequired = false)]
        public HaredWareCommonM CameraScalesG1E
        {
            get { return (HaredWareCommonM)this["CameraScalesG1"]; }
        }

        public static HaredWareCommonM GetSetCameraScalesG1
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesG1E; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CameraScalesG1E.Ip = value.Ip;
                iConfig.CameraScalesG1E.Port = value.Port;
                iConfig.CameraScalesG1E.UserName = value.UserName;
                iConfig.CameraScalesG1E.PassWord = value.PassWord;
                iConfig.CameraScalesG1E.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesG2
        [ConfigurationProperty("CameraScalesG2", IsRequired = false)]
        public HaredWareCommonM CameraScalesG2E
        {
            get { return (HaredWareCommonM)this["CameraScalesG2"]; }
        }

        public static HaredWareCommonM GetSetCameraScalesG2
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesG2E; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CameraScalesG2E.Ip = value.Ip;
                iConfig.CameraScalesG2E.Port = value.Port;
                iConfig.CameraScalesG2E.UserName = value.UserName;
                iConfig.CameraScalesG2E.PassWord = value.PassWord;
                iConfig.CameraScalesG2E.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CameraScalesG3
        [ConfigurationProperty("CameraScalesG3", IsRequired = false)]
        public HaredWareCommonM CameraScalesG3E
        {
            get { return (HaredWareCommonM)this["CameraScalesG3"]; }
        }

        public static HaredWareCommonM GetSetCameraScalesG3
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).CameraScalesG3E; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CameraScalesG3E.Ip = value.Ip;
                iConfig.CameraScalesG3E.Port = value.Port;
                iConfig.CameraScalesG3E.UserName = value.UserName;
                iConfig.CameraScalesG3E.PassWord = value.PassWord;
                iConfig.CameraScalesG3E.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion


        #region CardReader
        [ConfigurationProperty("CardReader", IsRequired = false)]
        public HaredWareCommonM CardReaderE
        {
            get { return (HaredWareCommonM)this["CardReader"]; }
        }

        public static HaredWareCommonM GetSetCardReader
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).CardReaderE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CardReaderE.Ip = value.Ip;
                iConfig.CardReaderE.Port = value.Port;
                iConfig.CardReaderE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CardReaderDC
        [ConfigurationProperty("CardReaderDC", IsRequired = false)]
        public HaredWareCommonM CardReaderDCE
        {
            get { return (HaredWareCommonM)this["CardReaderDC"]; }
        }

        public static HaredWareCommonM GetSetCardReaderDC
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).CardReaderDCE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CardReaderDCE.Ip = value.Ip;
                iConfig.CardReaderDCE.Port = value.Port;
                iConfig.CardReaderDCE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region CardReaderMW
        [ConfigurationProperty("CardReaderMW", IsRequired = false)]
        public HaredWareCommonM CardReaderMWE
        {
            get { return (HaredWareCommonM)this["CardReaderMW"]; }
        }

        public static HaredWareCommonM GetSetCardReaderMW
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).CardReaderMWE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.CardReaderMWE.Ip = value.Ip;
                iConfig.CardReaderMWE.Port = value.Port;
                iConfig.CardReaderMWE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region LengSheng
        [ConfigurationProperty("LengSheng", IsRequired = false)]
        public HaredWareCommonM LengShengE
        {
            get { return (HaredWareCommonM)this["LengSheng"]; }
        }

        public static HaredWareCommonM GetSetLengSheng
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).LengShengE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.LengShengE.Ip = value.Ip;
                iConfig.LengShengE.Port = value.Port;
                iConfig.LengShengE.Name = value.Name;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion


        #region UserInfo
        [ConfigurationProperty("UserInfo", IsRequired = false)]
        public UserInfo UserInfoE
        {
            get { return (UserInfo)this["UserInfo"]; }
        }
        public class UserInfo : ConfigurationElement
        {
            /// <summary>
            /// 用户名
            /// </summary>
            [DisplayName("用户名")]
            [ConfigurationProperty("LoginAccount", IsRequired = false)]
            public string LoginAccount
            {
                get { return this["LoginAccount"].ToString(); }
                set { this["LoginAccount"] = value; }
            }
            /// <summary>
            /// 密码
            /// </summary>
            [DisplayName("密码")]
            [ConfigurationProperty("PassWord", IsRequired = false)]
            public string PassWord
            {
                get { return this["PassWord"].ToString(); }
                set { this["PassWord"] = value; }
            }
            /// <summary>
            /// token
            /// </summary>
            [DisplayName("token")]
            [ConfigurationProperty("Token", IsRequired = false)]
            public string Token
            {
                get { return this["Token"].ToString(); }
                set { this["Token"] = value; }
            }
        }
        public static UserInfo GetSetuserInfo
        {
            get { return ((IConfig)ConfigurationManager.GetSection("IConfig")).UserInfoE; }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                iConfig.UserInfoE.LoginAccount = value.LoginAccount;
                iConfig.UserInfoE.PassWord = value.PassWord;
                iConfig.UserInfoE.Token = value.Token;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion

        #region Setters
        [ConfigurationProperty("Setters", IsRequired = false)]
        public Setters SettersE
        {
            get
            {
                return (Setters)this["Setters"];
            }
        }
        public class Setters : ConfigurationElement
        {

            /// <summary>
            /// HWKG
            /// </summary>
            [DisplayName("HWKG")]
            [ConfigurationProperty("HWKG", IsRequired = false)]
            public string HWKG
            {
                get
                {
                    return this["HWKG"].ToString();
                }
                set
                {
                    this["HWKG"] = value;
                }
            }
           
        }
        public static Setters GetSetSetters
        {
            get
            {
                return ((IConfig)ConfigurationManager.GetSection("IConfig")).SettersE;
            }
            set
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                IConfig iConfig = config.GetSection("IConfig") as IConfig;
                if(!string.IsNullOrWhiteSpace(value.HWKG)) iConfig.SettersE.HWKG = value.HWKG;
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("IConfig");
            }
        }
        #endregion



    }

}
